package com.agan.net.netty_tcp.client;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
public class HelloWorldClientHandler extends ChannelInboundHandlerAdapter {
    
    private int counter;

    
    private String str="bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbba";

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        String temp="";
	      byte[] req;
	      ByteBuf message;

	      //滑动窗体 递增
        for(int i=0;i<5000;i++){
            temp+=str;
        }
        req=temp.getBytes();
        System.out.println(req.length);
        //将上面的所有字符串作为一个消息体发送出去
        message = Unpooled.buffer(req.length);
        message.writeBytes(req);
        ctx.writeAndFlush(message);

        //滑动窗体 递减
//	     for(int y=5;y>=1;y--) {
//	         temp="";
//	         for(int i=0;i<5*y;i++){
//	             temp+=str;
//	         }
//	         req=temp.getBytes();
//	         System.out.println(req.length);
//	         //将上面的所有字符串作为一个消息体发送出去
//	         message = Unpooled.buffer(req.length);
//	         message.writeBytes(req);
//	         ctx.writeAndFlush(message);
//
//	         Thread.sleep(60000*2);
//	     }

        

    }

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        String buf = (String)msg;
        System.out.println("==================" + buf );
        System.out.println("++++++++++++++++++"+ (++counter));
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}